home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT01NEW.ZIP / TUT1.PAS < prev    next >
Pascal/Delphi Source File  |  1994-10-21  |  5KB  |  145 lines

  1. (*****************************************************************************)
  2. (*                                                                           *)
  3. (* TUTPROG1.CPP - VGA Trainer Program 1 (in Pascal)                          *)
  4. (*                                                                           *)
  5. (* "The VGA Trainer Program" is written by Denthor of Asphyxia.  However it  *)
  6. (* was limited to Pascal only in its first run.  All I have done is taken    *)
  7. (* his original release, translated it to C++, and touched up a few things.  *)
  8. (* I take absolutely no credit for the concepts presented in this code, and  *)
  9. (* am NOT the person to ask for help if you are having trouble.              *)
  10. (*                                                                           *)
  11. (* Program Notes : This program presents some basic video concepts: kicking  *)
  12. (*                 the computer into graphics mode, testing out two differ-  *)
  13. (*                 ent methods of putting pixels to the screen, and finally  *)
  14. (*                 re-entering text mode.                                    *)
  15. (*                                                                           *)
  16. (* Author        : Grant Smith (Denthor)      - smith9@batis.bis.und.ac.za   *)
  17. (*                                                                           *)
  18. (*                                                                           *)
  19. (*****************************************************************************)
  20.  
  21. {$X+}   (* This is a handy little trick to know. If you put this at the top
  22.            of your program, you do not have to set a variable when calling
  23.            a function, i.e. you may just say 'READKEY' instead of
  24.            'CH:=READKEY'                                                *)
  25.  
  26. USES Crt;           (* This has a few nice functions in it, such as the
  27.                        READKEY command.                                 *)
  28.  
  29. CONST VGA = $a000;  (* This sets the constant VGA to the segment of the
  30.                        VGA screen.                                      *)
  31.  
  32. {──────────────────────────────────────────────────────────────────────────}
  33. Procedure SetMCGA;  { This procedure gets you into 320x200x256 mode. }
  34. BEGIN
  35.   asm
  36.      mov        ax,0013h
  37.      int        10h
  38.   end;
  39. END;
  40.  
  41.  
  42. {──────────────────────────────────────────────────────────────────────────}
  43. Procedure SetText;  { This procedure returns you to text mode.  }
  44. BEGIN
  45.   asm
  46.      mov        ax,0003h
  47.      int        10h
  48.   end;
  49. END;
  50.  
  51.  
  52. {──────────────────────────────────────────────────────────────────────────}
  53. Procedure Cls (Col : Byte);
  54.    { This clears the screen to the specified color }
  55. BEGIN
  56.   Fillchar (Mem [$a000:0],64000,col);
  57. END;
  58.  
  59.  
  60. {──────────────────────────────────────────────────────────────────────────}
  61. Procedure INTPutpixel (X,Y : Integer; Col : Byte);
  62.    { This puts a pixel on the screen using interrupts. }
  63. BEGIN
  64.   asm
  65.      mov        ah,0Ch
  66.      mov        al,[col]
  67.      mov        cx,[x]
  68.      mov        dx,[y]
  69.      mov        bx,[1]
  70.      int        10h
  71.   end;
  72. END;
  73.  
  74.  
  75. {──────────────────────────────────────────────────────────────────────────}
  76. Procedure TestINTPutpixel;
  77.    { This tests out the speed of the INTPutpixel procedure. }
  78. VAR loop1,loop2 : Integer;
  79. BEGIN
  80.   For loop1:=0 to 319 do
  81.     For loop2:=0 to 199 do
  82.       INTPutpixel (loop1,loop2,Random (256));
  83.   Readkey;
  84.   Cls (0);
  85. END;
  86.  
  87.  
  88.  
  89. {──────────────────────────────────────────────────────────────────────────}
  90. Procedure MEMPutpixel (X,Y : Integer; Col : Byte);
  91.   { This puts a pixel on the screen by writing directly to memory. }
  92. BEGIN
  93.   Mem [VGA:X+(Y*320)]:=Col;
  94. END;
  95.  
  96.  
  97. {──────────────────────────────────────────────────────────────────────────}
  98. Procedure TestMEMPutpixel;
  99.    { This tests out the speed of the MEMPutpixel procedure. }
  100. VAR loop1,loop2 : Integer;
  101. BEGIN
  102.   For loop1:=0 to 319 do
  103.     For loop2:=0 to 199 do
  104.       MEMPutpixel (loop1,loop2,Random (256));
  105.   Readkey;
  106.   Cls (0);
  107. END;
  108.  
  109.  
  110.  
  111. {──────────────────────────────────────────────────────────────────────────}
  112. BEGIN    (* Of the main program *)
  113.   ClrScr;               { This clears the text Screen (CRT unit) }
  114.   Writeln ('What will happen is that I will clear the screen twice. After');
  115.   Writeln ('each clear screen you will have to hit a key. I will then fill');
  116.   Writeln ('the screen twice with randomlly colored pixels using two different');
  117.   Writeln ('methoods, after each of which you will have to hit a key. I will');
  118.   Writeln ('then return you to text mode.');
  119.   Writeln; Writeln;
  120.   Write ('Hit any kay to continue ...');
  121.   Readkey;
  122.  
  123.   SetMCGA;
  124.   CLS (32);
  125.   Readkey;
  126.   CLS (90);
  127.   Readkey;
  128.   TestINTPutpixel;
  129.   TestMEMPutpixel;
  130.   SetText;
  131.  
  132.   Writeln ('All done. This concludes the first sample program in the ASPHYXIA');
  133.   Writeln ('Training series. You may reach DENTHOR under the name of GRANT');
  134.   Writeln ('SMITH on the MailBox BBS, or leave a message to ASPHYXIA on the');
  135.   Writeln ('ASPHYXIA BBS. Get the numbers from Roblist, or write to :');
  136.   Writeln ('             Grant Smith');
  137.   Writeln ('             P.O. Box 270');
  138.   Writeln ('             Kloof');
  139.   Writeln ('             3640');
  140.   Writeln ('I hope to hear from you soon!');
  141.   Writeln; Writeln;
  142.   Write   ('Hit any key to exit ...');
  143.   Readkey;
  144. END.     (* Of the main program *)
  145.